import os
import unittest
import click
import time
from src.lib.BeautifulReport import BeautifulReport
from src.lib import CreateCases


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

@click.command()
@click.option('--cases', default='src/testcases/', help="case file path")
@click.option('--pattern', default='*.py', help="get cases file pattern")
@click.option(
        '--report',
        default='src/report/',
        help="generator report in path")
def run(cases, pattern, report):
    test_suite = unittest.defaultTestLoader.discover(cases, pattern=pattern)
    result = BeautifulReport(test_suite)
    result.report(filename='测试报告{}'.format(int(time.time())), description='测试deafult报告', log_path=report)
    disfiles = os.listdir(cases)
    for file in disfiles:
        if os.path.isfile(cases + file):
            os.remove(cases + file)
    # 每次执行测试后 回收掉所有自动生成的测试文件


if __name__ == '__main__':
    run()
